<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="/common/jsp/taglibs.jsp" %>
<!-- 用户列表 -->
<script type="text/javascript">
        
        function toassignRole(userId){
            $.dialog.open("${ctx}/userRole/assignRole?userId="+userId,{
                title: '分配角色', 
                width: 350,
                height: 200,
                close:function(){
                    loadMainHtml("${ctx}/user/toList?time="+new Date().getTime());
            }});
        }
        
        function addUser(){
        	$.dialog({
                title: '添加用户',
                content: $("#addUserDiv").html(),
                ok: function () {
                    $("#userForm").ajaxSubmit({
                        url:'${ctx }/user/add',
                        type:"POST",
                        dataType:'json',
                        success:function(data){
                            if(data.status=='success'){
                                showSuccess();
                                $.dialog.close();
                            }else{
                                showError();
                                $.dialog.close();
                            }
                            
                        }           
                    }); 
                },
                okVal:'提交',
                cancel: true,
                cancelVal:'取消',
                close:function(){
                    loadMainHtml("${ctx}/user/toList?time="+new Date().getTime());
                }
            });
        }
        
        function deleteUser(userId){
        	$.post("${ctx}/user/delete",{ids:userId},function(data){
        		if(data.status=='success'){
        			loadMainHtml("${ctx}/user/toList?time="+new Date().getTime());
                    showSuccess();
                }else{
                	loadMainHtml("${ctx}/user/toList?time="+new Date().getTime());
                    showError();
                }
        	},"json");
        }
        
        function deleteAllSelectedUser(){
        	var userId="";
            $.each($("input[name=userId]:checked"),function(i,n){
            	userId+=$(n).val()+",";
            });
            $.post("${ctx}/user/delete",{ids:userId},function(data){
                if(data.status=='success'){
                    loadMainHtml("${ctx}/user/toList?time="+new Date().getTime());
                    showSuccess();
                }else{
                    loadMainHtml("${ctx}/user/toList?time="+new Date().getTime());
                    showError();
                }
            },"json");
        }
</script>
        <div class="pad20"   style="font-size: 13px;line-height: 20px;" >
          <a href="javascript:void(0);" class="button" onclick="addUser();">
              <span class="ui-icon ui-icon-plusthick"></span>
                                      添加用户
          </a>
        </div>
        <div class="pad20">
          <table class="fullwidth"  cellspacing="0" border="0">
            <thead>
            <tr>
              <td><input type="checkbox" class="checkall" />全选</td>
              <td>名称</td>
              <td>描述</td>
              <td>操作</td>
            </tr>
            </thead>
             <tbody>
            <c:if test="${pageList!=null }">
             <c:forEach items="${pageList.list }" var="user"  varStatus="i">
              <tr <c:if test="${i.index%2!=0 }">class="odd"</c:if>>
              <td><input type="checkbox" name="userId" value="${user.id }"/></td>
               <td>${user.name }</td>
               <td>${user.description }</td>
               <td>
                   <span onclick="toassignRole(${user.id });">分配角色</span>
                   <span onclick="deleteUser(${user.id });">删除</span>
               </td>
              </tr>
             </c:forEach>    
            </c:if> 
            </tbody>   
          </table>
        </div>
        <div class="pad20">
        <div style="float:left">
           <a href="javascript:void(0);"  onclick="deleteAllSelectedUser();"  class="button tooltip" title="删除选中项"><span class="ui-icon ui-icon-trash"></span>删除选中</a>
        </div>
           <c:import url="/common/jsp/page.jsp">
             <c:param name="actionName">${ctx}/user/toList?</c:param>
           </c:import>
        </div>
        <!-- 增加用户 -->
        <div id="addUserDiv"  style="display:none;">
        <form id="userForm">
        <p>
           <label>姓名:</label>
           <input type="text"  name="name" class="sf"/>
        </p>
        <p>
           <label>密码:</label>
           <input type="text"  name="password" class="sf"/>
        </p>
        <p>
           <label>描述:</label>
           <textarea name="description" rows="5" cols="15"></textarea>
        </p>
        </form>
        </div> 
         <!-- 增加用户结束 -->
